/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.pattern.observer;

import java.util.*;

/**
 * The AbstractObservable class provide the basic implementation of Observable interface
 * 
 * @author Joe Choi
 * @version 1.0.0
 * @see Observable
 */
public class BaseObservable<E> implements Observable<E> {
	public BaseObservable() {
		observers = new ArrayList<Observer<E>>();
	}
	
	@Override
	public void register(Observer<E> observer) {
		observers.add(observer);
	}

	@Override
	public Observer<E> remove(Observer<E> observer) {
		return(observers.remove(observer) ? observer : null);
	}
	
	@Override
	public void notifyObserver(E event) {
		for(Observer<E> observer : observers) observer.notified(event);
	}
	
	protected List<Observer<E>> getObserver() {
		return(observers);
	}
	
	private List<Observer<E>> observers;
}
